package com.wef.demo.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.gfa4j.query.QueryInfo;
import com.gfa4j.wef.common.action.CommonQuery4ZTreeAction;
import com.gfa4j.wef.common.action.CommonQueryAction;
import com.gfa4j.wef.struts.BaseAction;
import com.gfa4j.wef.struts.QueryHandle;
import com.gfa4j.wef.utils.JSONUtil;

public class RegionAction extends BaseAction {
	public ActionForward queryTreeData(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// 1.组装QueryInfo
		QueryInfo queryInfo = CommonQueryAction.getQueryInfo(request);
		// 2.查询 并 转换成Json String
		List<?> list = (List<?>) QueryHandle.findByQuery(queryInfo);
		String jsonString = JSONArray.fromObject(
				CommonQuery4ZTreeAction.entitites2TreeObjects(list,
						"regionCode", "superRegionCode", "regionName",
						"regionName"), JSONUtil.getJsonConfig()).toString();

		// 3.输出到页面
		CommonQueryAction.outData2Page(jsonString, response);

		return null;
	}
}
